package com.chj233.myapp.mains;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.chj233.libapp.Constance;
import com.chj233.myapp.R;

@Route(path = Constance.MAIN_VIEW)//声明路径 后续其它模块都会根据这个路径来找到这个页面
public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ARouter.getInstance().inject(this);//页面注入
        findViewById(R.id.view1).setOnClickListener(this);
        findViewById(R.id.view2).setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.view1:
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        Bundle bundle = new Bundle();
                        bundle.putInt("user",1);
                        //跳转时，ARouter 会自动转入UI线程
                        ARouter.getInstance().build(Constance.GREEN_VIEW).with(bundle).navigation();
                    }
                }).start();
                break;
            case R.id.view2:
                ARouter.getInstance().build(Constance.BLUE_VIEW).navigation();
                break;
        }
    }
}